package del4;

import java.io.*;

public class FileInfo {
	public static void main(String[] args) throws IOException {
		String userInput = args[0];
		String type = null;
		if(args.length > 1) {
			String s = args[1];
			type = args[2];
		}
		
		File directory = new File(userInput);
		
		File[] list = directory.listFiles();
		int k = 0;
		long bytes = 0;
		if(type != null) {
			for(int i = 0; i < list.length; i++) {
				String fileString = list[i].toString();
				if(fileString.endsWith(type)) {
					k++;
					bytes += list[i].length();
				}
			}
			System.out.println(userInput+" contains "+k+" files of the type "+type+" with a total size of "+bytes+" bytes");
		} else {
			for(int i = 0; i < list.length; i++) {
				if(list[i].isFile()) {
					k++;
					bytes += list[i].length();
				}
			}
			System.out.println(userInput+" contains "+k+" files with a total size of "+bytes+" bytes");
		}
	}
}